<template>
  <div class="singer">
    <div class="singer-top">
      <div class="w1200">
        <div class="singer-hd">
          <div class="hd-left">
            <el-image :src="singer_detail.cover"></el-image>
          </div>
          <div class="hd-right">
            <div class="title">
              <h2>{{singer_detail.name}}</h2>
              <span><i class="el-icon-star-off"></i> 收藏</span>
            </div>
            <p v-if="singer_desc.briefDesc">
              {{ singer_desc.briefDesc }} <em>更多>></em>
            </p>
            <p v-else>暂无简介</p>
          </div>
        </div>
      </div>
    </div>
    <div class="singer-bottom">
      <div class="w1200">
        <div class="typeInfo">
          <div class="typeInfo-left">
                <em>作品集</em>
                <span :class="selectTypeInfo==='hot'?'active':''" @click="selectType('hot')">热门作品</span>
                <span :class="selectTypeInfo==='album'?'active':''" @click="selectType('album')">所有专辑</span>
                <span :class="selectTypeInfo==='mv'?'active':''" @click="selectType('mv')">相关MV</span>
          </div>
          <div class="typeInfo-right">
            <div class="play-collect" v-if="selectTypeInfo==='hot'">
              <div class="btn">
                <i
                  :class="[
                    isPlayed ? 'el-icon-video-pause' : 'el-icon-caret-right',
                  ]"
                ></i
                >立即播放
              </div>
              <div class="btn collect">
                <i class="el-icon-chat-dot-round"></i>添加到播放列表
              </div>
              <div class="btn collect">
                <i class="el-icon-star-off sam"></i>收藏热门
              </div>
            </div>
          </div>
        </div>
        <div class="bottom-songlist">
            <div class="hotsong" v-if="selectTypeInfo==='hot'">
                <hotsong :songList="hotSongs"></hotsong>
            </div>
             <div class="allalbum" v-if="selectTypeInfo==='album'">
                <album-list class="allalbum-list" :albumList="allAlbums"></album-list>
                <pagination :pageSize="pageSize" :total="total" @changePage=changePage></pagination>
            </div>
             <div class="simimv" v-if="selectTypeInfo==='mv'">
                <mv-list :newMvList="simiMv"></mv-list>
            </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import {formatSongInfo} from '@/utils/songs'
import Hotsong from '@/components/common/Song-list.vue'
import AlbumList from '@/components/common/Album-list.vue'
import MvList from '@/components/common/MvList.vue'
import Pagination from '@/components/common/Pagination.vue'
export default {
    components:{
        Hotsong,
        AlbumList,
        MvList,
        Pagination
    },
  data() {
    return {
      singer_desc: {}, //歌手描述
      singer_detail: {}, //歌手详情
      selectTypeInfo:'hot',
      singer_albumParams:{
          id:'',
          limit:30,
          offset:0
      },
      hotSongs:[],//热门单曲
      allAlbums:[],//所有专辑
      simiMv:[],
      total:0,
      pageSize:0
    };
  },
  async created() {
    const id = this.$route.query.id;
    this.pageSize = this.singer_albumParams.limit;
    this.singer_albumParams.id=id;
   await this.getsingerDetail(id);
   await this.getSingerDesc(id);
   await this.getSingerSong(id);
  },
  computed: {
    ...mapGetters(["isPlayed"]),
  },
  methods: {
    async getsingerDetail(id) {
      const res = await this.$api.getsingerDetail(id);
    //   console.log(res);
      this.singer_detail = res.data.artist;
    },
    async getSingerDesc(id) {
      const res = await this.$api.getSingerDesc(id);
    //   console.log(res);
      this.singer_desc = res;
    },
    async getSingerSong(id){
        const res = await this.$api.getSingerSong(id);
        res.hotSongs.forEach(item=>{
            this.hotSongs.push(formatSongInfo(item))
        })
        // console.log(this.hotSongs)
    },
    async getSingerAlbum(params){
        const res = await this.$api.getSingerAlbum(params);
        this.total=res.artist.albumSize;
        this.allAlbums=res.hotAlbums;
        // console.log(res)
    },
    async getSingerMv(id){
        const res = await this.$api.getSingerMv(id);
        this.simiMv=res.mvs
        // console.log(res)
    },
    selectType(type){
        this.selectTypeInfo=type;
        switch(type){
            case 'hot':
                this.getSingerSong(this.$route.query.id);
            break;
            case 'album':
                this.singer_albumParams.offset=0;
                this.getSingerAlbum(this.singer_albumParams)
            break;
            case 'mv':
                this.getSingerMv(this.$route.query.id)
            break;
        }
    },
    changePage(num){
        this.singer_albumParams.offset=(num-1)*this.pageSize;
        this.getSingerAlbum(this.singer_albumParams);
    }
  },
};
</script>
<style lang="less" scoped>
.w1200 {
  margin: 0 auto;
  width: 1200px;
  // border: 1px solid blue;
}
.singer-top {
  width: 100%;
  height: 352px;
  margin-top: -10px;
  background-color: #f4f4f4;
  .singer-hd {
    display: flex;
    height: 352px;
    padding: 40px 0;
    .hd-left {
      width: 200px;
      height: 200px;
      .el-image {
        border-radius: 50%;
        height: 100%;
        width: 100%;
      }
    }
    .hd-right {
      flex: 1;
      padding-left: 40px;
      .title {
        display: flex;
        align-items: center;
        height: 53px;
        margin-bottom: 10px;
      }
      h2 {
        font-size: 40px;
      }
      span {
        display: inline-block;
        width: 80px;
        height: 30px;
        background-color: #fff;
        border-radius: 14px;
        text-align: center;
        line-height: 30px;
        font-size: 14px;
        padding: 2px 10px;
        font-weight: 500;
        margin-left: 20px;
        color: #333;
        cursor: pointer;
      }
      p {
        line-height: 24px;
        color: #999;
        em {
          font-style: normal;
          color: #ff641e;
          cursor: pointer;
        }
      }
    }
  }
}
.play-collect {
  display: flex;
  width: 400px;
  .btn {
    width: 105px;
    height: 30px;
    border-radius: 50px;
    background-color: #ff641e;
    color: #fff;
    cursor: pointer;
    text-align: center;
    line-height: 30px;
    padding-left: 18px;
    position: relative;
    i {
      position: absolute;
      font-size: 20px;
      left: 12px;
      top: 4px;
    }
  }
  .collect {
    background-color: #f0f0f0;
    color: #333;
    margin-left: 5px;
    width: 140px;
    i {
      font-size: 15px;
      top: 7px;
    }
    .sam{
       left: 28px;
    }
  }
}

.singer-bottom {
  width: 100%;
  padding-top: 50px;
  .typeInfo {
    height: 40px;
    width: 100%;
    // border: 1px solid #ccc;
    display: flex;
    align-items: center;
    .typeInfo-left{
        flex:1;
        em{
            font-style: normal;
            font-size: 24px;
        }
        span{
            display: inline-block;
            padding: 0 20px;
            font-size: 16px;
            color: #333;
            cursor: pointer;
        }
        .active{
            position: relative;
            font-weight: 600;
        }
        .active::after{
            display: block;
            content: '';
            position: absolute;
            width: calc(100% - 40px);
            height: 5px;
            bottom: 0;
            left: 20;
            background-color: #ff641e;
            z-index: -1;
        }
    }
  }
}
.bottom-songlist{
    margin-top: 20px;
    padding-bottom: 80px;
    .allalbum-list{
        /deep/li{
            margin: 10px 6px;
        }
    }
}
</style>
